package com.bw.controller;

import com.bw.entity.User;
import org.spring.kun.common.TokenUtils;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;
import java.util.List;

@Controller
public class ListController {




    @RequestMapping("/list.do")
    public String list(Model model, HttpServletRequest request){
        // 从request中 获取cookie， 从cookie中获取token， 再解析token 得到用户  强转为user对象
        User userFromRequest = TokenUtils.getLoginUserFromRequest(request, User.class);
        model.addAttribute("nickName",userFromRequest.getNickName());
        model.addAttribute("avatarUrl",userFromRequest.getAvatarUrl());

        List<String> list = Arrays.asList("1", "2", "3", "4");
        model.addAttribute("list",list);
        return "list";
    }
}
